package com.jzo2o.customer.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.mapper.AgencyCertificationAuditMapper;
import com.jzo2o.customer.model.domain.AgencyCertificationAudit;
import com.jzo2o.customer.model.domain.WorkerCertificationAudit;
import com.jzo2o.customer.model.dto.request.AgencyCertificationAuditPageQueryReqDTO;
import com.jzo2o.customer.model.dto.response.AgencyCertificationAuditResDTO;
import com.jzo2o.mysql.utils.PageHelperUtils;
import org.springframework.stereotype.Service;
import com.jzo2o.customer.service.AgencyCertificationAuditService;

import java.util.Objects;

/**
 * 机构认证审核表(AgencyCertificationAudit)表服务实现类
 *
 * @author makejava
 * @since 2025-10-08 01:39:16
 */
@Service
public class AgencyCertificationAuditServiceImpl extends ServiceImpl<AgencyCertificationAuditMapper, AgencyCertificationAudit> implements AgencyCertificationAuditService {

    @Override       
    public PageResult<AgencyCertificationAuditResDTO> pageAudit(AgencyCertificationAuditPageQueryReqDTO agencyCertificationAuditPageQueryReqDTO) {
        return PageHelperUtils.selectPage(agencyCertificationAuditPageQueryReqDTO,
                ()->baseMapper.page(agencyCertificationAuditPageQueryReqDTO));
    }

    @Override
    public void aduit(Long id, Long certificationStatus, String rejectReason) {
        if (Objects.equals(certificationStatus,3L)&&Objects.isNull(rejectReason)) {
            throw new RuntimeException("请填写拒绝理由");
        }
        LambdaUpdateWrapper<AgencyCertificationAudit> agencyCertificationAuditLambdaUpdateWrapper
                = new LambdaUpdateWrapper<>();
        LambdaUpdateWrapper<AgencyCertificationAudit> query = agencyCertificationAuditLambdaUpdateWrapper
                .eq(AgencyCertificationAudit::getId, id)
                .set(AgencyCertificationAudit::getCertificationStatus, certificationStatus)
                .set(ObjectUtil.isNotNull(rejectReason), AgencyCertificationAudit::getRejectReason, rejectReason);
        baseMapper.update(null, query);

    }
}

